<body class="gr">

<div class="navBar">
	<a class="left" href="wap.php"><i class="return"></i></a>
	<div class="titleView">积分商城</div>
	<a class="right" href="wap.php?app=article&act=detail&id=7">积分规则</a>
</div>

<div class="goods-list main-padding-top width-wrap">
	<div class="pullRefresh">
		{if count($data.flashes)>0}
		<div class="pageView">
			<div class="slide">
				<ul>
					{foreach from=$data.flashes name=g item=g}
					<li ad_type="{$g->ad_type}" ad_content="{$g->ad_content}" pic="{$g->pic}"></li>
					{/foreach}
				</ul>
			</div>
			<div class="pager"></div>
		</div>
		<div class="tip">超值兑换</div>
		{/if}
		
		{if count($data.goods)>0}
		<ul class="list goods-item">
			{foreach from=$data.goods name=g item=g}
			<li>
				<a href="wap.php?app=goods&act=detail&goods_id={$g->id}&integral=1">
					<div class="pic" style="background-image:url({$g->default_pic});"></div>
					<div class="title"><div>{$g->name}</div><font class="btn"><b>立即兑换</b></font><span class="integral">{$g->integral}积分</span></div>
				</a>
			</li>
			{/foreach}
		</ul>
		{/if}
	</div>
</div>

<script>
var offset = $('.pullRefresh .list > li').length;
function createHtml(g){
	var html = '<li>\
		<a href="wap.php?app=goods&act=detail&goods_id='+g.id+'&integral=1">\
			<div class="pic" style="background-image:url('+g.default_pic+');"></div>\
			<div class="title"><div>'+g.name+'</div><font class="btn"><b>立即兑换</b></font><span class="integral">'+g.integral+'积分</span></div>\
		</a>\
	</li>';
	offset++;
	return html;
}
function setLists(){
	var width = ($('.pullRefresh').width()-10*3) / 2;
	$('.list li').width(width);
	$('.list a .pic').loadbackground();
}
function resize(){
	$('.pageView').autoHeight(320, 137);
	$('.pageView li').css({ width:$('.pageView').width(), height:$('.pageView').height() });
	$('.pageView').touchmove({
		pager : '.pager',
		drag : true,
		auto : 4000,
		autoWait : 4000,
		complete : function(){
			$('.pager').css('margin-left', -$('.pager').width()/2);
			setAds('.pageView .slide li');
		}
	});
}
$(window).resize(function(){
	resize();
	setLists();
});
$(function(){
	resize();
	setLists();
	setAds('.pageView .slide li');
	$('html, body').addClass('height-wrap').css('overflow', 'hidden');
	$('.goods-list').height($.window().height-$('.goods-list').padding().top);
	$('.pullRefresh').pullRefresh({
		header : true,
		footer : true,
		footerNoMoreText : '- END -',
		refresh : function(fn){
			var _this = this;
			offset = 0;
			$.getJSON('api.php?app=goods&act=index&integral=1', function(json){
				if(json.error!=0){ $.overloadError(json.msg);return }
				var html = '';
				if($.isArray(json.data.goods))for(var i=0; i<json.data.goods.length; i++)html += createHtml(json.data.goods[i]);
				_this.find('.list').html(html);
				setLists();
				fn();
			});
		},
		load : function(fn){
			var _this = this;
			$.getJSON('api.php?app=goods&act=index&integral=1', { offset:offset }, function(json){
				if(json.error!=0){ $.overloadError(json.msg);return }
				var html = '';
				if($.isArray(json.data.goods))for(var i=0; i<json.data.goods.length; i++)html += createHtml(json.data.goods[i]);
				_this.find('.list').append(html);
				setLists();
				fn();
			});
		}
	});
});
</script>